package com.ruoyi.supermarket.service.impl;

import java.util.List;

import com.ruoyi.common.constant.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.supermarket.mapper.AdvertiseMapper;
import com.ruoyi.supermarket.domain.Advertise;
import com.ruoyi.supermarket.service.AdvertiseService;

/**
 * 首页广告Service业务层处理
 * 
 * @author 李其伟
 * @date 2023/10/24
 */
@Service
public class AdvertiseServiceImpl implements AdvertiseService
{
    @Autowired
    private AdvertiseMapper advertiseMapper;

    /**
     * 查询首页广告
     * 
     * @param id 首页广告主键
     * @return 首页广告
     */
    @Override
    public Advertise selectAdvertiseById(Long id)
    {
        return advertiseMapper.selectAdvertiseById(id);
    }

    /**
     * 查询首页广告列表
     * 
     * @param advertise 首页广告
     * @return 首页广告
     */
    @Override
    public List<Advertise> selectAdvertiseList(Advertise advertise)
    {
        return advertiseMapper.selectAdvertiseList(advertise);
    }

    /**
     * 新增首页广告
     * 
     * @param advertise 首页广告
     * @return 结果
     */
    @Override
    public int insertAdvertise(Advertise advertise)
    {
        advertise.setPublishStatus(Constants.PUBLISH_STATUS_DOWN);
        advertise.setClickCount(0);
        advertise.setOrderCount(0);
        return advertiseMapper.insertAdvertise(advertise);
    }

    /**
     * 修改首页广告
     * 
     * @param advertise 首页广告
     * @return 结果
     */
    @Override
    public int updateAdvertise(Advertise advertise)
    {
        return advertiseMapper.updateAdvertise(advertise);
    }

    /**
     * 上下架首页广告
     *
     * @param advertise 首页广告
     * @return 结果return
     */
    @Override
    public int publishAdvertise(Advertise advertise) {
        Advertise ad = advertiseMapper.selectAdvertiseById(advertise.getId());
        ad.setPublishStatus(advertise.getPublishStatus());
        return advertiseMapper.updateAdvertise(ad);
    }
    /**
     * 批量删除首页广告
     * 
     * @param ids 需要删除的首页广告主键
     * @return 结果
     */
    @Override
    public int deleteAdvertiseByIds(Long[] ids)
    {
        return advertiseMapper.deleteAdvertiseByIds(ids);
    }

    /**
     * 删除首页广告信息
     * 
     * @param id 首页广告主键
     * @return 结果
     */
    @Override
    public int deleteAdvertiseById(Long id)
    {
        return advertiseMapper.deleteAdvertiseById(id);
    }
}
